﻿//tab逻辑
$(function () {

    let tabList = [
        {
            name: '个人资料',
            url: '/Setting/Profile.aspx'
        },
        {
            name: '截稿页设置',
            url: '/Setting/Resume.aspx'
        },
        {
            name: '作品顺序',
            url: '/Setting/Artwork.aspx'
        }
    ]

    tabList = tabList.map(item => {
        const isActive = location.href.lastIndexOf(item.url) > -1;
        return `<li class="${isActive ? 'layui-this' : ''} layui-tab-item" active-url="${item.url}">${item.name}</li>`
    });


    const tabNode = $([
        `<ul class="layui-tab-title">`,
            [...tabList],
        `</ul>`
    ].join(''));

    $('.layui-tab').append(tabNode)

    $('.layui-tab-item').click(function (item) {
        const redirectUrl = $(this).attr('active-url');
        location.href = redirectUrl;
    })
})


$(function () {
    layui.use(['upload', 'element', 'layer'], function () {
        var $ = layui.jquery
        , upload = layui.upload
        , element = layui.element
        , layer = layui.layer;

        //常规使用 - 普通图片上传
        var uploadInst = upload.render({
            elem: '.re-select'
          , url: '/Files/Upload.aspx' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
          , before: function (obj) {
          }
          , done: function (res) {
              $.ajax({
                  url: "/User/Handle.aspx",
                  method:"post",
                  data: {
                      action: "UpdateAvatar",
                      url:res.url
                  },
                  success: () => {
                      location.reload()
                  }
              })

          }
          , error: function () {

          }
          , progress: function (n, elem, e) {

          }
        });
    })


    //类型标签
    layui.config({
        base: '/Content/Scripts/'
    }).use(['inputTag'], function () {
        var inputTag = layui.inputTag;
        typeTag= inputTag.render({
            elem: '.typeTag',
            data: [...typeTagData],//初始值
            permanentData: [],//不允许删除的值
            removeKeyNum: 8,//删除按键编号 默认，BackSpace 键
            createKeyNum: 13,//创建按键编号 默认，Enter 键
            theme: "fairy-bg-info",
            beforeCreate: function (data, value) {//添加前操作，必须返回字符串才有效
                if (data.length < 3) {
                    return value;
                }
            },
            onChange: function (data, value, type) {
            }
        });

        $("#typeTag_id").find('.fairy-tag').on('click', function () {
            let value = this.innerText;
            typeTag.createItem(value)
        })
    })


    //风格标签
    layui.config({
        base: '/Content/Scripts/'
    }).use(['inputTag'], function () {
        var inputTag = layui.inputTag;
        styleTag = inputTag.render({
            elem: '.styleTag',
            data: [...styleTagData],//初始值
            permanentData: [],//不允许删除的值
            removeKeyNum: 8,//删除按键编号 默认，BackSpace 键
            createKeyNum: 13,//创建按键编号 默认，Enter 键
            theme: "fairy-bg-info",
            beforeCreate: function (data, value) {//添加前操作，必须返回字符串才有效
                if (data.length < 3) {
                    return value;
                }
            },
            onChange: function (data, value, type) {
            }
        });

        $("#styleTag_id").find('.fairy-tag').on('click', function () {
            let value = this.innerText;
            styleTag.createItem(value)
        })
    })


    //身份标签
    layui.config({
        base: '/Content/Scripts/'
    }).use(['inputTag'], function () {
        var inputTag = layui.inputTag;
        identityTag = inputTag.render({
            elem: '.identityTag',
            data: [...identityTagData],//初始值
            permanentData: [],//不允许删除的值
            removeKeyNum: 8,//删除按键编号 默认，BackSpace 键
            createKeyNum: 13,//创建按键编号 默认，Enter 键
            theme: "fairy-bg-info",
            beforeCreate: function (data, value) {//添加前操作，必须返回字符串才有效
                if (data.length < 1) {
                    return value;
                    
                }
            },
            onChange: function (data, value, type) {
            }
        });

        $("#identityTag_id").find('.fairy-tag').on('click', function () {
            let value = this.innerText;
            identityTag.createItem(value)
        })
    })


})


$(function () {
    const typeTagNodes = tagOptions.types.map(item=> `<span class="fairy-tag fairy-anim-fadein pointer">${item}</span>`).join("");
    $("#typeTag_id").append(typeTagNodes)

    const styleTagNodes = tagOptions.styles.map(item=> `<span class="fairy-tag fairy-anim-fadein pointer">${item}</span>`).join("");
    $("#styleTag_id").append(styleTagNodes)

    const identityTagNodes = tagOptions.identity.map(item=> `<span class="fairy-tag fairy-anim-fadein pointer">${item}</span>`).join("");
    $("#identityTag_id").append(identityTagNodes)
})